package com.foreknow.demo13;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class SetDemo {
    public static void main(String[] args) {
        //创建一个Set集合
        Set<Person> set = new HashSet<>();
        Person p1 = new Person();
        p1.setName("fender");
        Person p2 = new Person();
        p2.setName("gibson");
        Person p3 = new Person();
        p3.setName("BOSS");

        //向Set集合中添加元素
        set.add(p1);
        set.add(p2);
        set.add(p3);
        //获取Set集合中所有的元素
        Iterator<Person> it = set.iterator();
        while (it.hasNext()) {
            Person p = it.next();
            System.out.println(p.getName());
        }

    }
}
